package com.three.digit.chart;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;

import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class D3JCheckBox extends JCheckBox
{
    private static final long serialVersionUID = 1L;

    private XYSeries xySeries;
    private XYSeriesCollection xySeriesCollection;

    public D3JCheckBox (XYSeries xySeries, XYSeriesCollection xySeriesCollection)
    {
        super ((String) xySeries.getKey (), true);

        this.xySeries = xySeries;
        this.xySeriesCollection = xySeriesCollection;

        addListener ();
    }

    private void addListener ()
    {
        this.addActionListener (new ActionListener ()
        {
            public void actionPerformed (ActionEvent e)
            {
                if (((JCheckBox) e.getSource ()).isSelected ())
                {
                    xySeriesCollection.addSeries (xySeries);
                }
                else
                {
                    xySeriesCollection.removeSeries (xySeries);
                }
            }
        });
    }
}
